/**
 * com.cnhis.his.customer.service.Val1Service.java
 */
package com.mbmed.doctor.medadvice.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.login.bo.Bck1Bo;
import com.mbmed.doctor.login.mapper.Bck1;
import com.mbmed.doctor.medadvice.bo.Val1Bo;
import com.mbmed.doctor.medadvice.mapper.Bbx1;
import com.mbmed.doctor.medadvice.mapper.Val1;

/**
 * @file  Val1Service.java
 * @author 刘武
 * @version 0.1
 * @todo	Val1服务操作接口
 * Copyright(C), 2013-2014
 *		 Shenzhen Coordinates Software Development Co., Ltd.
 * History
 *   	1. Date: 2014-11-01 01:39:27
 *      	Author: 刘武
 *      	Modification: this file was created
 *   	2. ...
 */
@Path("/val1")
@Component
public class Val1Service {
	
	private static Logger logger = Logger.getLogger(Val1.class);
	
	@Autowired
	private Val1Bo val1Bo;
	
	@Autowired
	
	private Bck1Bo bck1Bo;
	@Context
	Request request;

	
	/**
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public List<Val1> getAll() throws Exception{
        List<Val1> list = new ArrayList<Val1>();
        return val1Bo.getAll();        
    }
	
    /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("{id}")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public Val1 getVal1(@PathParam("id") String id) throws Exception{
    	Val1 val1 = null;
    	return val1Bo.get(id);        
    }
	
	
	

	/**
     * 根据不同分类检索数据
     * @param id 与数据库中主键对应的值
     * @return type :  药品：门诊按规格下医嘱，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getadivqueryallergy")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo  getAdivQueryAllergy(
    		@QueryParam("vaa01") java.lang.String vaa01,
    		@QueryParam("bbx01") java.lang.String bbx01,
    		@QueryParam("bbx05") java.lang.String bbx05,
    		@QueryParam("bck01") java.lang.String bck01
    		) throws Exception{
		ModelVo modelvo = new ModelVo();
		Map<String,Object> paramap = new HashMap<String,Object>();
		Map<String,Object> paramap2 = new HashMap<String,Object>();
		Map<String,Object> paramap3 = new HashMap<String,Object>();
		
		int vaa01v = Integer.parseInt(vaa01);
		int bbx01b = Integer.parseInt(bbx01);
//		int bck1b = Integer.parseInt(bck01);
		
		paramap.put("vaa01", vaa01v);
		paramap.put("bbx01", bbx01b);
	
		List<Val1> val1list = new ArrayList<Val1>();
//		Val1  val1 = new Val1();
		val1list = val1Bo.getAdivQueryAllergy(paramap);
		
//		paramap2.put("bck1", bck1b);
//		paramap2.put("bbx01", bbx01b);
//		Bck1 bck1 = new Bck1();
//		bck1 = bck1Bo.getAdviceExecBck1(paramap2);
		
		paramap3.put("val1list", val1list);
//		paramap3.put("bck1", bck1);
		
		modelvo.setMap(paramap3);
    	return modelvo;
	}
	
    /**
     * 向数据库中插入一条记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : 返回插入操作是否成功
     * @throws Exception
     */
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Val1 saveVal1(
			@FormParam("val01") java.lang.Integer val01,
			@FormParam("vaa01") java.lang.Integer vaa01,
			@FormParam("bbx01") java.lang.Integer bbx01,
			@FormParam("bbx05") java.lang.String bbx05,
			@FormParam("val05") java.lang.String val05,
			@Context HttpServletResponse servletResponse
	) throws Exception {
		Val1 val1 = new Val1();
		val1.setVal01(val01);
		val1.setVaa01(vaa01);
		val1.setBbx01(bbx01);
		val1.setBbx05(bbx05);
		val1.setVal05(val05);

		return val1 = val1Bo.save(val1);

	}
	/**
     * 删除数据库中与传入的值对象对应的记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : boolean 返回删除操作是否成功
     * @throws Exception
     */
	@DELETE
	@Path("{id}")
	public boolean removeVal1(@PathParam("id") String id) throws Exception{
		if(id == null) return false;
    	return val1Bo.remove(id);

	}
	
}
